Skip to content

Add Temporal Nexus Operation Handler#2842

Open
Quinn-With-Two-Ns wants to merge 7 commits intotemporalio:masterfrom
Quinn-With-Two-Ns:temporal-nexus-operation-handler
Open

Add Temporal Nexus Operation Handler#2842
Quinn-With-Two-Ns wants to merge 7 commits intotemporalio:masterfrom
Quinn-With-Two-Ns:temporal-nexus-operation-handler

Conversation

@Quinn-With-Two-Ns
Copy link
Copy Markdown
Contributor

@Quinn-With-Two-Ns Quinn-With-Two-Ns commented Apr 14, 2026

Add TemporalOperationHandler for generic Nexus operations

Summary

  • Adds TemporalOperationHandler, a generic OperationHandler implementation that maps Nexus operations to Temporal workflows via a composable StartFunction
  • Adds TemporalNexusClient for starting workflows (typed and untyped) from within Nexus operation handlers
  • Supports subclassing TemporalOperationHandler to customize cancel behavior by overriding cancelWorkflowRun
  • Extracts shared workflow start logic into NexusStartWorkflowHelper, reused by both WorkflowRunOperation and the new handler

Test plan

  • GenericHandlerTypedStartWorkflowTest — typed workflow with return value
  • GenericHandlerTypedProcTest — typed void workflow
  • GenericHandlerUntypedStartWorkflowTest — untyped workflow start
  • GenericHandlerSyncResultTest — synchronous result path
  • GenericHandlerCancelTest — cancel with default and custom behavior

Note

Medium Risk
Touches Nexus start/cancel dispatch and operation-token parsing/validation, which can affect interoperability and cancellation semantics. Changes are largely additive/experimental but include refactors on the workflow-start path.

Overview
Adds an experimental generic Nexus handler API: TemporalOperationHandler dispatches start/cancel requests to user-provided logic and returns either sync results (TemporalOperationResult.sync) or async workflow-run tokens (TemporalOperationResult.async) via a new TemporalNexusClient wrapper for typed/untyped workflow starts.

Refactors shared start-workflow/link-attachment behavior into NexusStartWorkflowHelper and reuses it from WorkflowRunOperationImpl, and generalizes token handling by renaming WorkflowRunOperationToken to OperationToken plus adding OperationTokenUtil.loadOperationToken for type-based cancel dispatch.

Adds coverage for the new generic handler behaviors (typed starts, void procs, untyped starts, sync results, cancel path, and guard against multiple async starts per invocation) and updates existing async operation/token tests accordingly.

Reviewed by Cursor Bugbot for commit a33ff01. Bugbot is set up for automated code reviews on this repo. Configure here.

@Quinn-With-Two-Ns Quinn-With-Two-Ns marked this pull request as ready for review April 14, 2026 22:33
@Quinn-With-Two-Ns Quinn-With-Two-Ns requested a review from a team as a code owner April 14, 2026 22:33
TestMultiArgWorkflowFunctions.TestNoArgsWorkflowProc.class,
wf -> {
wf.proc();
return null;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maciejdudko @GregoryTravis This is one issue I found with the approach, due to ambiguity in the lambda we have to return null here for workflows that don't return anything.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit ee62ae7. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant